package com.example.gobang.ApplicationAutoTest.common;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeOptions;
import io.github.bonigarcia.wdm.WebDriverManager;

import java.time.Duration;
import java.util.concurrent.TimeUnit;

/**
 * @author vivi
 * @description
 * @date 2024-08-01
 */
public class AutoTestUtils {
    public static ChromeDriver chromeDriver;
    public static EdgeDriver edgeDriver;

    // 创建驱动对象
    public static ChromeDriver createChromeDriver() {
        if (chromeDriver == null) {
            //WebDriverManager.chromedriver().setup();
            System.setProperty("webdriver.chrome.driver", "C:\\Program Files\\Google\\Chrome\\Application\\chromedriver.exe");
            ChromeOptions options = new ChromeOptions();
            options.addArguments("--remote-allow-origins=*"); // 允许所有请求
            chromeDriver = new ChromeDriver(options);
            // 添加隐式等待
            Duration duration = Duration.ofSeconds(10);
            long millis = duration.toMillis();
            chromeDriver.manage().timeouts().implicitlyWait(millis, TimeUnit.MILLISECONDS);
        }
        return chromeDriver;
    }

    public static EdgeDriver createEdgeDriver() {
        if (edgeDriver == null) {
            EdgeOptions options = new EdgeOptions();
            options.addArguments("--remote-allow-origins=*"); // 允许所有请求
            edgeDriver = new EdgeDriver(options);
            // 添加隐式等待
            edgeDriver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
        }
        return edgeDriver;
    }

}





















